<?php
//require("lib/PHPMailer_5.2.0/class.phpmailer.php");
//include("lib/PHPMailer_5.2.0/class.pop3.php");
//include("lib/PHPMailer_5.2.0/class.smtp.php");
include 'lib/user.php';
include 'lib/member.php';
include 'lib/mail.php';
include 'config/config.php';

$config=new config();
$config->connect();
$error="";
$reset=false;
 if(isset($_POST['reset_pass'])){
 
		$User_Dao=new User_Dao();
		//echo $User_Dao->cek_email($_POST['email']);
		if($User_Dao->cek_email($_POST['email'])==true) {
				$user=$User_Dao->get_ByEmail($_POST['email']);
				//echo $_POST['email'];
				//var_dump($user);
				$pass_lama = $user->password;
				$pass_baru = $User_Dao->randomPass();
				$user->password= $pass_baru;
				$User_Dao->edit_pass($user);
				$mail = new Mail();
				

				$mail->To = $user->email; 
				$mail->Name = $user->email;
				$mail->From = "teamhotl.com@gmail.com";
				$mail->FromName = "hotl.com"; 
				$mail->Subject = "Reset Password Akun hot-l.com";                              

				$mail->Body = "<p>Anda telah mengirimkan permintaan untuk melakukan reset password akun hot-l.com pada tanggal ".date('d F Y')." pukul ".date('H:i:s') .".</p>
						<p>Email Anda : ".$user->email." </p>
						<p>Password baru Anda adalah : ".$User_Dao->randomPass()." </p>
						<p>Salam,<br />
						Hot-L Team. </p>";

								
				if($mail->Send_mail()){
					//$reset=true;
					echo "<script>alert('Perubahan password telah dilakukan dan dikirim ke Email Anda.'); </script>";
				}else {
					$user->password = $pass_lama;
					$User_Dao->edit_pass($user);
					echo "<script>alert('Maaf, saat ini kami tidak dapat melakukan pengiriman email. Silahkan lakukan beberapa waktu lagi.'); </script>";
					//$reset=false;
					
					
				}
		} else {
			echo "<script>alert('Email tidak ditemukan.'); </script>";
		}
		}
		
	
?>
<?php include("header.php") ?>
<?php include("menu_kiri.php") ?>

<div id="body">

<div class="topbox">

<?php 
	//if($reset==false){ 
		
		echo "Silahkan masukan email, perubahan password akan dikirimkan kepada Anda melalui email.";
		echo "<form name=\"form1\" method=\"post\" action=\"reset_password.php\">
				<input type=\"hidden\" name=\"reset_pass\"><br/>
				Email : <input type=\"text\" size=\"32\" name=\"email\"> <input type=\"submit\" name=\"submit\" value=\"submit\" onclick=\"return validasi();\">
				</form><br />";
		echo $error;

		//	}
	//if($reset==true){ echo "Perubahan password telah dilakukan dan dikirim ke Email Anda.";}
?>
		 			  
</div>

</div>
          
         <div class="clear"></div>
         <?php include("footer.php") ?>
<script>
function validasi(){
	var x = document.form1.email.value;
	if(x==""){
		alert('Isikan email terlebih dahulu');
		return false;
	}
}
</script>
		